# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2022年11月11日
"""
from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.shared import Inches

document = Document()
paragraph = document.add_paragraph('Lorem ipsum dolor sit amet.')
prior_paragraph = paragraph.insert_paragraph_before('Lorem ipsum')
document.add_heading('The REAL meaning of the universe')
document.add_heading('The role of dolphins', level=2)
document.add_heading('The role of dolphins level 0', level=0)

document.add_page_break()

table = document.add_table(rows=2, cols=2)
cell = table.cell(0, 1)
cell.text = 'parrot, possibly dead'

row = table.rows[1]
row.cells[0].text = 'Foo bar to you.'
row.cells[1].text = 'And a hearty foo bar to you too sir!'
# for row in table.rows:
#     for cell in row.cells:
#         print(cell.text)
# print(len(table.rows))
# print(len(table.columns))
row = table.add_row()

# get table data -------------
items = (
	(7, '1024', 'Plush kittens'),
	(3, '2042', 'Furbees'),
	(1, '1288', 'French Poodle Collars, Deluxe'),
)

# add table ------------------
document.add_paragraph("=========")
table = document.add_table(1, 3)

# populate header row --------
heading_cells = table.rows[0].cells
heading_cells[0].text = 'Qty'
heading_cells[1].text = 'SKU'
heading_cells[2].text = 'Description'

# add a data row for each item
for item in items:
	# print(item)
	cells = table.add_row().cells
	cells[0].text = str(item[0])
	cells[1].text = item[1]
	cells[2].text = item[2]
table.style = 'Table Grid'

# for style in document.styles:
# 	if style.type==WD_STYLE_TYPE.TABLE:
# 		print(style.name)

document.add_picture('./Python.png')
document.add_picture('./Python.png', width=Inches(1.0))

document.add_paragraph('Lorem ipsum dolor sit amet.', style='List Bullet')

paragraph = document.add_paragraph('Lorem ipsum ')
run = paragraph.add_run('dolor')
run.bold = True
paragraph.add_run(' sit amet.')

paragraph = document.add_paragraph()
paragraph.add_run('Lorem ipsum ')
paragraph.add_run('dolor').bold = True
paragraph.add_run(' sit amet.')

paragraph = document.add_paragraph('Normal text, ')
paragraph.add_run('text with emphasis.', 'Emphasis')

document.save("07Quickstart.docx")